import * as actionTypes from './actionTypes'
import   axios from 'axios'

//所有用户方法为异步action

var url = 'http://www.jluquery.ngrok.cc/'

//初始化学校信息，教学日期/
export function initData(schoolID) {
    return {
        type:actionTypes.SCHOOL_INFO,
        payload:{
            schoolID:schoolID
        }
    }
}

//初始化用户cookie信息
export function initUserCookie(user,psw) {
    //发送异步action
    return dispatch => axios({
        url: url+'api/',
        method: 'post',
        data: {
            username: user,
            password: psw
        },
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }).then((cookie)=>{
        dispatch(saveUserCookie(cookie))
    }).catch((error)=>{
        console.log(error)
    })
}
//保存用户cookie信息
export function saveUserCookie(cookie) {
    return {
        type: actionTypes.SAVE_COOKIE,
        payload: {
            userCookie: cookie
        }
    }
}